////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2010 Gabriel Montagné Láscaris-Comneno and Alberto
//  Brealey-Guzmán.
//
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//
////////////////////////////////////////////////////////////////////////////////

package com.rojored.utils
{

import org.flexunit.assertThat;
import org.hamcrest.object.equalTo;

/**
 *  Tests for modulo.
 */
public class TestModulo
{

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructor
     */
    public function TestModulo()
    {
        super();
    }

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    [Test(description="Positive divisor under dividend values")]

    /**
     *  Test value under dividend.
     */
    public function positiveDividendUnderDivisor():void
    {
        assertThat(MathUtil.modulo(5, 10), equalTo(5));
    }

    [Test(description="Positive divisor over dividend")]

    /**
     *   Test value over dividend.
     */
    public function positiveValueOverDivisor():void
    {
        assertThat(MathUtil.modulo(15, 10), equalTo(5));
    }

    [Test(description="Negative dividend under divisor")]

    /**
     *   Test value over dividend.
     */
    public function negativeDividendUnderDivisor():void
    {
        assertThat(MathUtil.modulo(-1, 10), equalTo(9));
    }

    [Test(description="Wrap around positive divisor")]

    /**
     *   Test wrap-around positive divisor modulo.
     */
    public function wrapAroundDivisorModule():void
    {
        assertThat(MathUtil.modulo(32, 10), equalTo(2));
    }

    [Test(description="Wrap-around negative divisors")]

    /**
     *   Negative divisors should wrap around dividend to produce a positive
     *   number.
     */
    public function wrapAroundNegativeDivisor():void
    {
        assertThat(MathUtil.modulo(-32, 10), equalTo(8));
    }

    [Test(description="Positive dividend, negative divisor")]

    /**
     *   Positive dividend should wrap around negative divisor to produce a
     *   negative remainder.
     */
    public function positiveDivisorNegativeDividend():void
    {
        assertThat(MathUtil.modulo(2, -10), equalTo(-8));
    }
}
}
